package controller;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JTextField;
import model.Client;
import model.MessageOutput;
import model.Server;
import view.ClientView;

/**
 *
 * @author Dustin & Maik
 */
public class ClientController implements ActionListener {
    private Client client;
    private MessageOutput output;

    public ClientController() {
        output = new ClientView(this);
        client = new Client(output);
        client.connect("localhost");
        client.start();
    }

    public void actionPerformed(ActionEvent ev) {
        if(ev.getActionCommand().equals("INPUT")) {
            JTextField source = (JTextField) ev.getSource();
            String input = source.getText();
            client.sendMessage(input);
            output.addMessage("C: " + input);
            source.setText("");
        }
    }

    public static void main(String[] args) {
        new Server();
        new ClientController();
    }
}
